package yunjiao.designpatterns.observer;

import lombok.extern.slf4j.Slf4j;

/**
 * 入口
 *
 * @author yangyunjiao
 */
@Slf4j
public class App {
    public static void main(String[] args) {
        // 创建新闻发布者
        NewsPublisher techNews = new NewsPublisher("科技新闻");
        NewsPublisher sportsNews = new NewsPublisher("体育新闻");

        // 创建订阅者
        Observer alice = new EmailSubscriber("Alice", "alice@example.com");
        Observer bob = new SMSSubscriber("Bob", "13800138000");
        Observer charlie = new AppNotificationSubscriber("Charlie");

        // 订阅科技新闻
        techNews.registerObserver(alice);
        techNews.registerObserver(bob);

        // 订阅体育新闻
        sportsNews.registerObserver(bob);
        sportsNews.registerObserver(charlie);

        System.out.println("\n=== 发布新闻 ===");
        // 发布新闻
        techNews.publishNews("人工智能新突破：GPT-5即将发布");
        System.out.println();
        sportsNews.publishNews("奥运会：中国代表团再获3枚金牌");

        System.out.println("\n=== 取消订阅 ===");
        // Bob取消订阅科技新闻
        techNews.removeObserver(bob);

        System.out.println("\n=== 再次发布新闻 ===");
        techNews.publishNews("元宇宙技术发展趋势分析");

    }


}
